﻿
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using System.Web;



namespace Yyd.AspNetCore.Middleware
{


    /// <summary>
    /// 兼容网关2.0 get 网关2.0 get 会多一次编码
    /// </summary>
    public class GateWayHandleMiddleware
    {
        private readonly RequestDelegate _next;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="next"></param>
        public GateWayHandleMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        /// <summary>
        /// 兼容网关2.0 get
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task Invoke(HttpContext context)
        {
            var request = context.Request;

            if (request.Method.ToLower() == "get" && request.QueryString.HasValue)
            {
                request.QueryString = new QueryString(HttpUtility.UrlDecode(request.QueryString.ToString()));
            }

            await _next(context);
        }
    }
}

